from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from fastapi.middleware.wsgi import WSGIMiddleware

from routers.user import router as user_router
from routers.diet_plan import rooter as chat_router
from routers.calorie import router as calorie_router
from routers.user_center import router as center_router
from routers.imageprocess import router as iamgeprocess_router
from routers.recipe import router as recipe_router
from routers.admin import flask_app

app = FastAPI(
    title="果壳悦食",
    version="1.0.0",
    description="管理用户的饮食记录和健康信息"
)

# 跨域配置
origins = ["*"]
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"]
)

# 注册app模块
app.include_router(user_router, prefix="/user")
app.include_router(chat_router, prefix="/chat")
app.include_router(calorie_router, prefix="/calorie")
app.mount("/admin", WSGIMiddleware(flask_app))
app.include_router(center_router, prefix="/user_center")
app.include_router(recipe_router, prefix="/recipe_work")
app.include_router(iamgeprocess_router, prefix="/imageprocess")

if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8000)
